package adv328;

import adv327.Sex;
import adv327.Student;

import java.util.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class SetDemo {
    public static void main(String[] args) {
        Set<String> s = new HashSet<>();
        s.add("tiger");
        s.add("pig");
        s.add("dog");
        s.add("dog");
        s.add("dog");
        s.add("cat");
        System.out.println(s.size());
        System.out.println(s);
        System.out.println(">>>>>遍历>>>>>>");
        for (String str : s) {
            System.out.print(str + " ");
        }
        System.out.println();
        System.out.println(">>>>>>>>>>迭代器遍历>>>>>>>>>>>>>>");
        Iterator<String> ir = s.iterator();
        while (ir.hasNext()) {//有没有下一个
            String next = ir.next();//找到下一个；
            //remove：删除
            System.out.print(next + " ");
        }
        System.out.println();
        System.out.println(">》》》》》转换成数组遍历：");
        String[] objects = s.toArray(new String[0]);//!!!
        for (int i = 0; i < objects.length; i++) {
            System.out.print(objects[i] + " ");
        }
        System.out.println();
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>");
        Set<Student> s3 = new HashSet<>();
        s3.add(new Student("刘1", 22, Sex.男));
        s3.add(new Student("王智睿", 18, Sex.男));
        s3.add(new Student("胡汪洋", 27, Sex.男));
        s3.add(new Student("yiwenlong", 22, Sex.男));
        s3.add(new Student("赵俊杰", 17, Sex.男));
        s3.add(new Student("赵俊杰", 23, Sex.妖));
        System.out.println(s3.size());
        for (Student st : s3) {
            System.out.println(st);
        }
    }
}
